---
--- Created by root.
--- DateTime: 17-11-20 下午6:01
---

local _OBJ = {}
_OBJ.get = {}
_OBJ.post = {}

function _OBJ.getPath(self)
    --ngx.say(ngx.var.request_uri)
    --ngx.say(ngx.var.uri)
    --ngx.exit(200)
    local uri = string.sub(ngx.var.uri, 2)
    local args = lfc:split(uri, "/")
    return args
end

function _OBJ.post()
    ngx.req.read_body()
    local postargs = ngx.req.get_post_args()
    return postargs
end

function _OBJ.get(self)
    return self:args()
end

function _OBJ.args(self)
    local argsPath = lfc:split(string.sub(ngx.var.request_uri,2),'/')

    local len = table.getn(argsPath)
    local argsArgs = {}
    if len<2 and argsPath[1] =="" then
        return {}
    end
    local argsPa = lfc:split(argsPath[len],'?')

    if table.getn(argsPa)<2 then
        return argsPath
    else
        argsPath[len] = argsPa[1]
        argsPa[2]  = lfc:split(argsPa[2],"&")

        for i, v in pairs(argsPa[2]) do
            if v~="" then
                local temp = lfc:split(v,'=')
                if table.getn(temp) ==2 then
                    argsArgs[temp[1]] = temp[2]
                end
            end
        end
    end
    --合并path和args
    local commonArgs = argsPath
    for i, v in pairs(argsArgs) do
        commonArgs[i] = v
    end

    return commonArgs

end

return _OBJ